<?php
  $username = $_POST["username"];
  $password = $_POST["password"];

  header("Content-Type:text/html;charset=utf-8");
  $conn = mysqli_connect('localhost','root','123456','gz2104'); 
 
  $sql = "SELECT *  FROM `login` WHERE `username` = '$username' AND `password` = '$password'";
  // 去表中查询
  $res = mysqli_query($conn,$sql);
  

  if(!$res){
    die('数据库链接错误' . mysqli_error($conn));
}

//   // 解析查询结果
  $row = mysqli_fetch_assoc($res);

// print_r ($row);

if(!$row){
  die('用户名密码错误');
}
// echo "登入成功";


  // 可以判断
  // 如果 $row 有东西证明我用你给我的用户名和密码查到数据了
  // 如果 $row 没有东西证明我用你给我的用户名和密码没有查到数据
  
    // 设置cookie
    setcookie("login","1",0,"/","localhost");
    setcookie("username",$username,0,"/","localhost");
    header("location: ../pages/home.html");
    
    // header("location: ../pages/login.html");
 
  
?>
